<template>
  <div class="student">
    <h1>{{ msg }}</h1>
    <h3>学生姓名:{{ name }}</h3>
    <h3>性别：{{ sex }}</h3>
    <h3>年龄：{{ myAge }}</h3>
    <button @click="addAge">年龄++</button>
  </div>
</template>

<script>
export default {
  name: "Student",
  data() {
    return { msg: "学生信息", myAge: this.age };
  },

  methods: {
    addAge() {
      this.myAge++;
    },
  },

  // 1.接收数据简单写法
  // props: ["name", "sex", "age"],
  // 2.接受数据的同时：进行数据类型限制
  // props: {
  //   name: String,
  //   sex: String,
  //   age: Number,
  // },

  // 3.接收数据的同事：进行数据类型校验+是否必填校验+默认值设置
  props: {
    name: {
      type: String,
      required: true,
    },
    sex: {
      type: String,
      required: true,
    },
    age: {
      type: Number,
      default: 16,
    },
  },
};
</script>

<style>
.student {
  background-color: orange;
}
</style>